#ifndef UDPSOCKET_H
#define UDPSOCKET_H

#include <QUdpSocket>
#include <QDebug>

class UdpSocket : public QUdpSocket
{
    Q_OBJECT
public:
    explicit UdpSocket(QObject *parent = nullptr);
    ~UdpSocket();

    void bindPort(quint16 port);
    void sendData(const QHostAddress &address, quint16 port, const QByteArray &data);
    int enable_debug = 1;
    void setDebug(int debug){enable_debug = debug;}
signals:
    void dataReceived(const QHostAddress &address, quint16 port, const QByteArray &data);
    void errorOccurred(const QString &errorString);

private slots:
    virtual void onReadyRead();
    virtual void handleError(QAbstractSocket::SocketError error);

private:
    void printDebugInfo(const QString &message);
};

#endif // UDPSOCKET_H
